<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增应聘人员信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-user-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">招聘信息：</label>
                <div class="col-sm-8">
                    <select id="recruitId" name="recruitId" class="form-control" th:onchange="selectContent()">
                        <option th:each="info : ${infos}" th:text="${info['recruitName']}" th:value="${info['recruitId']}" th:field="*{recruitInfo.recruitId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">招聘内容：</label>
                <div class="col-sm-8">
                    <select id="contentId" name="contentId" class="form-control">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">性别：</label>
                <div class="col-sm-8">
                    <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">身份证号：</label>
                <div class="col-sm-8">
                    <input name="idCard" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">手机号码：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学历：</label>
                <div class="col-sm-8">
                    <select name="educateName" class="form-control m-b" th:with="type=${@dict.getType('basic_educate_name')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学位：</label>
                <div class="col-sm-8">
                    <select name="degreeName" class="form-control m-b" th:with="type=${@dict.getType('basic_educate_degree')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">毕业学校：</label>
                <div class="col-sm-8">
                    <input name="schoolName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">所学专业：</label>
                <div class="col-sm-8">
                    <input name="majorName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">毕业时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="finishTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出生日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="birthday" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传附件：</label>
                <div class="col-sm-8">
                    <input accept="*/*" id="file" name="file" onchange="gen_size()" type="file">
                    <font color="red" class="pull-left mt10">
                        提示：请选择上传附件！
                    </font>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "recruit/user"
        $("#form-user-add").validate({
            onkeyup: false,
            rules:{
                phonenumber:{
                    isPhone:true
                },
                idCard:{
                    isIdentity:true,
                    remote: {
                        url: prefix + "/checkIdCardUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "idCard" : function() {
                                return $.common.trim($("#idCard").val());
                            },
                            "recruitId" : function() {
                                return $("#recruitId").val();
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
            },
            focusCleanup: true
        });

        $(function (){
            selectContent();
        })

        // 根据产品查询规格
        function selectContent() {
            $("#contentId").empty();
            var recruitId = $("#recruitId").val();
            if(recruitId != ''){
                $.ajax({
                    type: "post",
                    url: ctx + "recruit/content/contentList",
                    dataType: "json",
                    data: {"recruitId" : recruitId},
                    success: function(r) {
                        if (r.code == web_status.SUCCESS) {
                            var contentList = r.data;
                            for (var i = 0; i < contentList.length; i++){
                                var content = contentList[i];
                                var html = '<option value = "' + content.contentId + '">' + content.postName + "[" + content.postCode + "]" + '</option>';
                                $("#contentId").append(html);
                            }
                        } else {
                            $.modal.msgError(r.msg);
                        }
                        $.modal.closeLoading();
                    }
                });
            }
        }

        $("input[name='birthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='finishTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function gen_size(){
            var file = document.getElementById("file").files[0];
            var size = file.size;
            if(size > 100 * 1024 * 1024){
                $.modal.alertError("超出最大限制：100M");
                return;
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData($('#form-user-add')[0]);
                $.operate.saveFile(prefix + "/add", formData);
            }
        }
    </script>
</body>
</html>